import _regeneratorRuntime from "@babel/runtime/regenerator";
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";

/**
 * service 数据模型
 * @date: 2019-12-16
 */
import request from 'utils/request';
import { CPAAS_PLATFORM } from 'utils/config';
import { parseParameters, filterNullValueObject, isTenantRoleLevel, getCurrentOrganizationId } from 'utils/utils';
var prefix = isTenantRoleLevel() ? "".concat(CPAAS_PLATFORM, "/v1/").concat(getCurrentOrganizationId()) : "".concat(CPAAS_PLATFORM, "/v1");
/**
 * 查询弹性域模型
 */

export function queryList(_x) {
  return _queryList.apply(this, arguments);
}
/**
 *
 * @param {modelId} 根据modelId查询模型
 */

function _queryList() {
  _queryList = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(params) {
    var query;
    return _regeneratorRuntime.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            query = filterNullValueObject(parseParameters(params));

            if (query.noPaging) {
              delete query.noPaging;
              delete query.page;
              delete query.size;
            }

            return _context.abrupt("return", request("".concat(prefix, "/customize/model/list"), {
              query: query
            }));

          case 3:
          case "end":
            return _context.stop();
        }
      }
    }, _callee);
  }));
  return _queryList.apply(this, arguments);
}

export function queryModelDetail(_x2) {
  return _queryModelDetail.apply(this, arguments);
}
/**
 * 新建弹性域模型
 */

function _queryModelDetail() {
  _queryModelDetail = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(params) {
    return _regeneratorRuntime.wrap(function _callee2$(_context2) {
      while (1) {
        switch (_context2.prev = _context2.next) {
          case 0:
            return _context2.abrupt("return", request("".concat(prefix, "/customize/model/detail"), {
              query: params
            }));

          case 1:
          case "end":
            return _context2.stop();
        }
      }
    }, _callee2);
  }));
  return _queryModelDetail.apply(this, arguments);
}

export function createModel(_x3) {
  return _createModel.apply(this, arguments);
}
/**
 * 更新弹性域模型
 */

function _createModel() {
  _createModel = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(params) {
    return _regeneratorRuntime.wrap(function _callee3$(_context3) {
      while (1) {
        switch (_context3.prev = _context3.next) {
          case 0:
            return _context3.abrupt("return", request("".concat(prefix, "/customize/model/create"), {
              method: 'POST',
              body: params
            }));

          case 1:
          case "end":
            return _context3.stop();
        }
      }
    }, _callee3);
  }));
  return _createModel.apply(this, arguments);
}

export function modifyModel(_x4) {
  return _modifyModel.apply(this, arguments);
}
/**
 * 获取特定服务下的所有表名
 */

function _modifyModel() {
  _modifyModel = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(params) {
    return _regeneratorRuntime.wrap(function _callee4$(_context4) {
      while (1) {
        switch (_context4.prev = _context4.next) {
          case 0:
            return _context4.abrupt("return", request("".concat(prefix, "/customize/model/modify"), {
              method: 'POST',
              body: params
            }));

          case 1:
          case "end":
            return _context4.stop();
        }
      }
    }, _callee4);
  }));
  return _modifyModel.apply(this, arguments);
}

export function queryTablesList(_x5) {
  return _queryTablesList.apply(this, arguments);
}
/**
 * 获取模型下的所有字段
 */

function _queryTablesList() {
  _queryTablesList = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(params) {
    var query;
    return _regeneratorRuntime.wrap(function _callee5$(_context5) {
      while (1) {
        switch (_context5.prev = _context5.next) {
          case 0:
            query = filterNullValueObject(params);
            return _context5.abrupt("return", request("".concat(prefix, "/customize/model/list/tables"), {
              query: query
            }));

          case 2:
          case "end":
            return _context5.stop();
        }
      }
    }, _callee5);
  }));
  return _queryTablesList.apply(this, arguments);
}

export function queryFieldsList(_x6) {
  return _queryFieldsList.apply(this, arguments);
}
/**
 * 刷新字段
 */

function _queryFieldsList() {
  _queryFieldsList = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6(params) {
    var query;
    return _regeneratorRuntime.wrap(function _callee6$(_context6) {
      while (1) {
        switch (_context6.prev = _context6.next) {
          case 0:
            query = filterNullValueObject(params);
            return _context6.abrupt("return", request("".concat(prefix, "/model/field/list"), {
              query: query
            }));

          case 2:
          case "end":
            return _context6.stop();
        }
      }
    }, _callee6);
  }));
  return _queryFieldsList.apply(this, arguments);
}

export function refreshField(_x7) {
  return _refreshField.apply(this, arguments);
}
/**
 * 新建字段
 */

function _refreshField() {
  _refreshField = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7(params) {
    var query;
    return _regeneratorRuntime.wrap(function _callee7$(_context7) {
      while (1) {
        switch (_context7.prev = _context7.next) {
          case 0:
            query = filterNullValueObject(params);
            return _context7.abrupt("return", request("".concat(prefix, "/model/field/refresh"), {
              query: query
            }));

          case 2:
          case "end":
            return _context7.stop();
        }
      }
    }, _callee7);
  }));
  return _refreshField.apply(this, arguments);
}

export function createField(_x8) {
  return _createField.apply(this, arguments);
}
/**
 * 查询关联模型
 */

function _createField() {
  _createField = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee8(params) {
    return _regeneratorRuntime.wrap(function _callee8$(_context8) {
      while (1) {
        switch (_context8.prev = _context8.next) {
          case 0:
            return _context8.abrupt("return", request("".concat(prefix, "/model/field/create"), {
              method: 'POST',
              body: params
            }));

          case 1:
          case "end":
            return _context8.stop();
        }
      }
    }, _callee8);
  }));
  return _createField.apply(this, arguments);
}

export function queryModelRelationList(_x9) {
  return _queryModelRelationList.apply(this, arguments);
}
/**
 * 修改字段
 */

function _queryModelRelationList() {
  _queryModelRelationList = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee9(params) {
    var query;
    return _regeneratorRuntime.wrap(function _callee9$(_context9) {
      while (1) {
        switch (_context9.prev = _context9.next) {
          case 0:
            query = filterNullValueObject(params);
            return _context9.abrupt("return", request("".concat(prefix, "/model/relation/list"), {
              query: query
            }));

          case 2:
          case "end":
            return _context9.stop();
        }
      }
    }, _callee9);
  }));
  return _queryModelRelationList.apply(this, arguments);
}

export function modifyField(_x10) {
  return _modifyField.apply(this, arguments);
}
/**
 * 刪除字段
 */

function _modifyField() {
  _modifyField = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee10(params) {
    return _regeneratorRuntime.wrap(function _callee10$(_context10) {
      while (1) {
        switch (_context10.prev = _context10.next) {
          case 0:
            return _context10.abrupt("return", request("".concat(prefix, "/model/field/modify"), {
              method: 'POST',
              body: params
            }));

          case 1:
          case "end":
            return _context10.stop();
        }
      }
    }, _callee10);
  }));
  return _modifyField.apply(this, arguments);
}

export function removeField(_x11) {
  return _removeField.apply(this, arguments);
}
/**
 * 新建关系模型
 */

function _removeField() {
  _removeField = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee11(params) {
    return _regeneratorRuntime.wrap(function _callee11$(_context11) {
      while (1) {
        switch (_context11.prev = _context11.next) {
          case 0:
            return _context11.abrupt("return", request("".concat(prefix, "/model/field"), {
              method: 'DELETE',
              query: params
            }));

          case 1:
          case "end":
            return _context11.stop();
        }
      }
    }, _callee11);
  }));
  return _removeField.apply(this, arguments);
}

export function createRelation(_x12) {
  return _createRelation.apply(this, arguments);
}
/**
 * 删除关系模型
 */

function _createRelation() {
  _createRelation = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee12(params) {
    return _regeneratorRuntime.wrap(function _callee12$(_context12) {
      while (1) {
        switch (_context12.prev = _context12.next) {
          case 0:
            return _context12.abrupt("return", request("".concat(prefix, "/model/relation/create"), {
              method: 'POST',
              body: params
            }));

          case 1:
          case "end":
            return _context12.stop();
        }
      }
    }, _callee12);
  }));
  return _createRelation.apply(this, arguments);
}

export function deleteRelation(_x13) {
  return _deleteRelation.apply(this, arguments);
}
/**
 * 保存关系模型
 */

function _deleteRelation() {
  _deleteRelation = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee13(params) {
    return _regeneratorRuntime.wrap(function _callee13$(_context13) {
      while (1) {
        switch (_context13.prev = _context13.next) {
          case 0:
            return _context13.abrupt("return", request("".concat(prefix, "/model/relation"), {
              method: 'DELETE',
              query: params
            }));

          case 1:
          case "end":
            return _context13.stop();
        }
      }
    }, _callee13);
  }));
  return _deleteRelation.apply(this, arguments);
}

export function saveRelationn(_x14) {
  return _saveRelationn.apply(this, arguments);
}

function _saveRelationn() {
  _saveRelationn = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee14(params) {
    return _regeneratorRuntime.wrap(function _callee14$(_context14) {
      while (1) {
        switch (_context14.prev = _context14.next) {
          case 0:
            return _context14.abrupt("return", request("".concat(prefix, "/model/relation/modify"), {
              method: 'POST',
              body: params
            }));

          case 1:
          case "end":
            return _context14.stop();
        }
      }
    }, _callee14);
  }));
  return _saveRelationn.apply(this, arguments);
}